package com.chumi.bootstrap.service.demo;

import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chumi.bootstrap.mapper.expand.demo.DemoMapper;
import com.chumi.bootstrap.mapper.expand.tsys.UserMapper;
import com.chumi.bootstrap.mapper.standard.demo.TtApplicationUserMapper;
import com.chumi.bootstrap.model.standard.demo.TtApplicationUser;
import com.chumi.bootstrap.model.standard.demo.TtApplicationUserCriteria;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.llsfw.core.exception.SystemException;
import com.llsfw.core.pagequery.PageInterceptor;
import com.llsfw.core.pagequery.PageResult;

@Service
public class TtApplicationUserService{
    
	private static final Logger LOG = LogManager.getLogger();
	
    @Autowired
    private TtApplicationUserMapper taum;
    
    @Autowired
    private UserMapper um;    
	
	public List<TtApplicationUser> getUserList(){
		TtApplicationUserCriteria example = new TtApplicationUserCriteria();
		example.or().andLoginNameLike("1");
		List<TtApplicationUser> list = taum.selectByExample(null);
		return list;
	}
	
	public Boolean checkUser(String loginName){
		TtApplicationUserCriteria example = new TtApplicationUserCriteria();
		example.or().andLoginNameEqualTo(loginName);
		int count = taum.countByExample(example);
		if(count==0){
			return false;
		}else{
			return true;
		}
	}	

    public PageResult getUserListByPageQuery(int pagesize, int page, TtApplicationUser user) throws SystemException {
        PageInterceptor.startPage(pagesize,page);
        List<Map<String, Object>> list = um.userPageQuery(user.getLoginName(),user.getUserName());
        PageResult pr = PageInterceptor.endPage(list);
        LOG.debug(pr.getTotalRecords());
        return pr;
    }
	
}
